#!/usr/bin/env python
# Create: 2019/3/8
__author__ = '749B'

import requests
from orionsdk import SwisClient

from utils.base64p import b64decode_str

npm_server = "network.shuxun.net"
username = "API_IT"
passwordb64 = "MTc0V3BtK0FQMkxFbWdsQkdCZVllWVl6djBKV2ZYS1dMM2x0SVY5RmRMdG5KMHViVTJibFFzd2lzNTMxNV9pdDAwMGIwMDBk"
password = b64decode_str(passwordb64)
swis = SwisClient(npm_server, username, password)

requests.packages.urllib3.disable_warnings()

# ip_addr = "192.168.201.120"
# results = swis.query("SELECT Uri FROM Orion.Nodes WHERE IP=@ip_addr", ip_addr=ip_addr)
cpsl = "CPSL00000802"
results = swis.query("SELECT Uri FROM Orion.NPM.Interfaces WHERE Alias LIKE @cpsl", cpsl='%' + cpsl + '%')
print(results)

uri = results['results'][0]['Uri']
obj = swis.read(uri + '/')
for k, v in obj.items():
    print(k, ': ', v)
